<!DOCTYPE html>
<html>
{include file="public/header" /}
<body>
<style>
  .layui-input-inline{
    width: 400px !important;
  }
</style>

<div class="layui-fluid" id="app" style="margin-top: 0px">
  <div class="layui-row layui-col-space15">
    <div class="layui-col-md12">
      <div class="layui-card" >
        <!--<div class="layui-card-header">商品列表</div>-->
        <div class="layui-card-body">

          <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
            <ul class="layui-tab-title">
              <li class="" onclick="go('selectpinpai')">品牌列表</li>
              <li class="layui-this"><a href="#">新增品牌</a></li>

            </ul>
            <div class="layui-tab-content" style="padding-left: 0px;padding-right: 0px">


              <div class="layui-tab-item layui-show" style="padding-top: 15px">
                <form class="layui-form " action="" style="margin-top: 10px">

                  <div class="layui-form-item">
                    <label class="layui-form-label">名称</label>
                    <div class="layui-input-block">
                      <input type="text" name="pinpai" value=""  class="layui-input">
                    </div>
                  </div>

                  <div class="layui-form-item">
                    <label class="layui-form-label">图片</label>

                    <div class="layui-input-inline " style="width: auto;">

                      <div class="layui-upload-drag" id="pic1" style="padding: 2px">
                        <img class="layui-upload-img" style="width: 120px;height: 120px; object-fit: cover;" src="/res/img/logo.png" id="im">
                        <input type="hidden" name="pinpai_logo" value="" >
                      </div>

                    </div>
                  </div>

                  <div class="layui-form-item" >
                    <div class="layui-input-block" style="padding-top: 15px">
                      <button class="layui-btn" type="button" lay-submit lay-filter="pinpai">确认</button>
                      <button type="reset" class="layui-btn layui-btn-primary" onclick="restart()">重新添加</button>
                    </div>
                  </div>
                </form>
              </div>

            </div>
          </div>


        </div>


      </div>

    </div>


  </div>
</div>



<script>

    layui.use(['form','upload'], function () {
        var $ = layui.$
            , layer = layui.layer
            , form = layui.form;
        var upload = layui.upload;


        //监听提交
        form.on('submit(pinpai)', function (obj) {
//            layer.msg(JSON.stringify(obj.field));
            $.post("{:url('newpinpai')}", obj.field, function (res) {
                if (res.code == 1) {
                    console.log(res);
                    var id=res.data.id;
                    var name=res.data.pinpai;
                    // console.log(id);
                    // console.log(name);
                    parent.selectpp(id,name);
                    parent.layer.closeAll();
                    // layer.msg(res.msg, {icon: 1});
                    // $('#pic1 img').attr('src','/res/img/thumb.png');
                    // $('.layui-form')[0].reset();
                    // return false;

                } else {
                    layer.msg(res.msg, {icon: 2}, function () {

                    })
                    return false;
                }

            });
            return false;
        });

        //拖拽上传
        upload.render({
            elem: '#pic1'
            ,url: '/tool/qiniu/upload'
            ,before:function () {
                layer.load(2);
            }
            ,done: function(res){
                layer.closeAll();
                console.log(res)
                $('#pic1 img').attr('src',res.data.url);
                $('#pic1 input').val(res.data.pic);
            }
        });
    });
    //重新选择图片
    function restart(){
        $('#im').attr('src','/res/img/logo.png');
    }
</script>
